﻿using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Localization;
using Orchard.Logging;
using Utils.WidgetInserter.Models;

namespace Utils.WidgetInserter.Handlers {
    [UsedImplicitly]
    public class SettingsPartHandler : ContentHandler {
        public SettingsPartHandler(IRepository<SettingsPartRecord> repository) {
            T = NullLocalizer.Instance;
            Logger = NullLogger.Instance;

            Filters.Add(new ActivatingFilter<SettingsPart>("Site"));
            Filters.Add(StorageFilter.For(repository));
        }

        public new ILogger Logger { get; set; }
        
        public Localizer T { get; set; }

        protected override void GetItemMetadata(GetContentItemMetadataContext context) {
            if (context.ContentItem.ContentType != "Site")
                return;
            base.GetItemMetadata(context);
            context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Widget Inserter")));
        }
    }
}